﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}

<script src="~/Content/adminDefault/js/default.js"></script>
<script>
    $(function () {
        InitialPage();
        GetTree();
        GetGrid();
    });
    var _itemId = "";
    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 165.5);
            }, 200);
            e.stopPropagation();
        });
    }

    function GetTree() {
        var item = {
            // height: $(window).height() - 344.5,
            url: "../../PropertyManage/SecurityPatrol/GetTreeListItem",
            onnodeclick: function (item) {
                _itemId = item.id;
                $('#btn_Search').trigger("click");
            }
        };
        //初始化
        $("#itemTree").treeview(item);
    }


    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var queryJson = $("#queryCondition").GetWebControls();
        queryJson["SPIId"] = _itemId;
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            url: "../../PropertyManage/SecurityPatrol/GetList",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 165.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "SPLId", index: "SPLId", hidden: true },
                { label: "项目编号", name: "ICode", index: "ICode", width: 150, align: "center", sortable: false },
                { label: "项目名称", name: "IName", index: "IName", width: 150, align: "center", sortable: false },
                { label: "楼盘名称", name: "PStructName", index: "PStructName", width: 150, align: "center", sortable: false },
                { label: "线路编号", name: "Code", index: "Code", width: 150, align: "center" },
                { label: "线路名称", name: "Name", index: "Name", width: 150, align: "center" },
                {
                    label: "频次", name: "Frequency", index: "Frequency", width: 150, sortable: false, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        switch (rowObject.Unit) {
                            case 0: return rowObject.UnitNum + "天" + cellvalue + "次";
                            case 1: return rowObject.UnitNum + "周" + cellvalue + "次";
                            case 2: return rowObject.UnitNum + "月" + cellvalue + "次";
                            case 3: return rowObject.UnitNum + "季" + cellvalue + "次";
                            case 4: return rowObject.UnitNum + "年" + cellvalue + "次";
                        }
                    }
                },
              //  { label: "完成次数", name: "Count", index: "Count", width: 100, align: "center" }
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortname: 'CreateDate',
            sortorder: 'desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function (status) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            },
          //  subGrid: true,
            //subGridRowExpanded: function (subgrid_id, row_id) {
            //    var SPLId = $("#gridTable").jqGrid('getRowData', row_id)['SPLId'];
            //    var subgrid_table_id = subgrid_id + "_t";
            //    var subhtml = "";
            //    subhtml += '<div><table id="' + subgrid_table_id + '"></table></table></div>';
            //    $("#" + subgrid_id).html(subhtml);
            //    $("#" + subgrid_table_id).jqGrid({
            //        url: "../../PropertyManage/SecurityPatrol/GetResult",
            //        postData: {
            //            SPLId: SPLId
            //        },
            //        caption: "巡更线路记录",
            //        datatype: "json",
            //        height: 170,
            //        colModel: [
            //    { label: "主键", name: "SPRId", hidden: true },
            //    { label: "线路ID", name: "SPLId", hidden: true },
            //    { label: "执行人名称", name: "ExecManName", index: "ExecManName", width: 80, align: "center" },
            //    { label: "执行时间", name: "ExecDate", index: "ExecDate", width: 80, align: "center" },
            //    {
            //        label: "状态", name: "Status", index: "Status", width: 150, align: "center",
            //        formatter: function (cellvalue, options, rowObject) {
            //            switch (cellvalue) {
            //                case 0: return "未完成";
            //                case 1: return "已完成";
            //                case 2: return "异常完成";
            //                case 3: return "异常终止";
            //                default: return "未完成";
            //            }
            //        }
            //    },
            //    { label: "开始时间", name: "StatrtDate", index: "StatrtDate", width: 80, align: "center" },
            //    { label: "结束时间", name: "EndDate", index: "EndDate", width: 100, align: "center" },
            //    { label: "异常描述", name: "ExecptionMemo", index: "ExecptionMemo", width: 80, align: "center" }
            //        ],
            //        pager: false,
            //        rowNum: "1000",
            //        rownumbers: true,
            //        hidegrid: false,
            //        shrinkToFit: false,
            //        gridview: true,
            //        onSelectRow: function () {
            //            selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            //        },
            //        gridComplete: function () {
            //            $("#" + this.id).setSelection(selectedRowIndex, false);
            //            $('#' + this.id).closest("div.ui-jqgrid-view")
            //            .children("div.ui-jqgrid-titlebar")
            //            .css("text-align", "center")
            //            .children("span.ui-jqgrid-title")
            //            .css("float", "none");
            //        },
            //        //ondblClickRow: function (rowid, iRow, iCol, e) {
            //        //    var obj = $("#" + this.id).getRowData(rowid);
            //        //    dialogOpen({
            //        //        id: "Form",
            //        //        title: "安全巡更记录明细",
            //        //        url: '../../PropertyManage/SecurityPatrol/AreaIndex?SPRId=' + obj.SPRId + '&SPLId=' + obj.SPLId,
            //        //        width: "1024px",
            //        //        height: "600px",
            //        //        callBack: function (iframeId) {
            //        //            top.frames[iframeId].AcceptClick();
            //        //        }
            //        //    });
            //        //}
            //    });
            //}
        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = $("#queryCondition").GetWebControls();
            queryJson["SPIId"] = _itemId;
            $gridTable.jqGrid('setGridParam', {
                url: "../../PropertyManage/SecurityPatrol/GetList",
                postData: { queryJson: JSON.stringify(queryJson) },
                page: 1
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }

    //新增
    function btn_add() {
        dialogOpen({
            id: "Form",
            title: '新增巡更路线',
            url: '/PropertyManage/SecurityPatrol/Form?SPIId=' + _itemId,
            width: "1100px",
            height: "850px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    };

    //编辑
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("SPLId");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form",
                title: '编辑巡更路线',
                url: '/PropertyManage/SecurityPatrol/Form?keyValue=' + keyValue,
                width: "1100px",
                height: "850px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
    };

    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("SPLId");
        if (keyValue) {
            $.RemoveForm({
                url: "../../PropertyManage/SecurityPatrol/RemoveForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的数据！', 0);
        }
    }

    //设置巡更项目
    function btn_Item() {
        dialogOpen({
            id: "Form",
            title: '设置巡更项目',
            url: '/PropertyManage/SecurityPatrol/ItemIndex',
            width: "1100px",
            height: "750px",
            btn: null,
            //callBack: function (iframeId) {
            //    top.frames[iframeId].AcceptClick();
            //}
        });
    };

    //设置巡更内容
    function btn_Content() {
        dialogOpen({
            id: "Form",
            title: '设置巡更内容',
            url: '/PropertyManage/SecurityPatrol/ContentIndex',
            width: "1100px",
            height: "750px",
            btn:null,
            //callBack: function (iframeId) {
            //    top.frames[iframeId].AcceptClick();
            //}
        });
    };
</script>

<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel" style="height:98.5%;">
            <div class="panel-Title">巡更项目信息</div>
            <div id="itemTree"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="panel-Title">巡更路线信息</div>
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr>
                            <td>
                                <div id="queryCondition" class="btn-group">
                                    <a class="btn btn-default dropdown-text" data-toggle="dropdown">选择条件</a>
                                    <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                                    <ul class="dropdown-menu">
                                        <li><a data-value="Code">编号</a>
                                        <li><a data-value="Name">名称</a>
                                    </ul>
                                </div>
                            </td>
                            <td style="padding-left: 2px;">
                                <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                            </td>
                            <td style="padding-left: 5px;">
                                <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                        <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                        <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                    </div>
                    <div class="btn-group">
                        <a id="lr-more" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                            <i class="fa fa-reorder"></i>&nbsp;更多设置<span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu pull-right">
                            <li id="lr-item"><a onclick="btn_Item()"><i class="fa fa-tags"></i>&nbsp;巡更项目设置</a></li>
                            <li id="lr-Content"><a onclick="btn_Content()"><i class="fa fa-tags"></i>&nbsp;巡更内容设置</a></li>
                        </ul>
                    </div>
                    <script>$('.toolbar').authorizeButton()</script>
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
</div>
